For Each loops are bad, mmmKay?
I avoid them for 2 main reasons:
1. Index loops are faster.
2. You cant modify a list inside a For Each loop.
I'll explain.
This will fail at the remove call:
For Each str As String In lstStr
'test for something
If str = "boosh"
lstStr.Remove(str)
End If
Loop
It fails because you have changed the list count and therefor the index.
This however, will work:
For i As Integer = lstStr.Count -1 To 0 Step -1
'test for something
If lstSt...
Continue reading ...